<template>
  <div class="icons">
    <swiper v-if="iconLength" :options="swiperOption">
     <swiper-slide v-for="(page, index) of pages" :key="index">
      <div class="icon" v-for="item in page" :key="item.id">
       <div class="icon_img">
         <img :src="item.imgUrl" />
       </div>
       <p class="icon_text">{{item.desc}}</p>
     </div>
     </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcon',
  props: {
    icon: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.icon.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    },
    iconLength () {
      return this.icon.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mini.styl'
  .icons >>> .swiper-container
   height 0
   padding-bottom 50%
   width 100%
  .icon
   height 0
   width 25%
   padding-bottom 25%
   float left
   position relative
   .icon_img
    position absolute
    box-sizing border-box
    padding .1rem
    top 0
    left 0
    right 0
    bottom  .44rem
    img
     width 100%
     height 100%
   .icon_text
    position absolute
    bottom 0
    left 0
    right 0
    line-height .44rem
    height .44rem
    text-align center
    color $darkTextColor
    ellipis()
</style>
